"""
This is the interface that allows for creating nested lists.
You should not implement it, or speculate about its implementation
"""
class NestedInteger(object):
   def __init__(self, value=None):
       """
       If value is not specified, initializes an empty list.
       Otherwise initializes a single integer equal to value.
       """
       self.value = value if value is not None else [] # 如果value不为None，则赋值给self.value，否则赋值给[]

   def isInteger(self):
       """
       @return True if this NestedInteger holds a single integer, rather than a nested list.
       :rtype bool
       """
       return isinstance(self.value, int) # 如果self.value是int，则返回True，否则返回False

   def add(self, elem):
       """
       Set this NestedInteger to hold a nested list and adds a nested integer elem to it.
       :rtype void
       """
       self.value.append(elem) # 将elem添加到self.value中

   def setInteger(self, value):
       """
       Set this NestedInteger to hold a single integer equal to value.
       :rtype void
       """
       self.value = value # 将value赋值给self.value

   def getInteger(self):
       """
       @return the single integer that this NestedInteger holds, if it holds a single integer
       Return None if this NestedInteger holds a nested list
       :rtype int
       """
       return self.value # 如果self.value是int，则返回self.value，否则返回None

   def getList(self):
       """
       @return the nested list that this NestedInteger holds, if it holds a nested list
       Return None if this NestedInteger holds a single integer
       :rtype List[NestedInteger]
       """
       return self.value # 如果self.value是list，则返回self.value，否则返回None


# 方法一：Python3 递归函数 比官方更清晰易懂
class NestedIterator1:
    def __init__(self, nestedList: [NestedInteger]):
        self.l = []

        # 递归函数
        def pending_nums(nestedList):
            # 对于nestedList的每个元素进行遍历
            for element in nestedList:
                # 如果这个元素是单个的数字则保存在我们的列表中
                if element.isInteger():
                    self.l.append(element.getInteger())
                # 如果这个元素不是数字而是nestedList
                else:
                    # 获取当前的nestedList
                    eeNest = element.getList()
                    # 进行重复递归即可
                    pending_nums(eeNest)

        pending_nums(nestedList)
        # 当前访问索引
        self.index = 0
        # 总的数字个数
        self.lenth = len(self.l)

    def next(self) -> int:
        # 返回当前索引的元素值，索引+1
        value = self.l[self.index]
        self.index += 1
        return value

    def hasNext(self) -> bool:
        # 根据索引和列表长判断是否还有下一个元素
        return self.index < self.lenth


# Your NestedIterator object will be instantiated and called as such:
# i, v = NestedIterator(nestedList), []
# while i.hasNext(): v.append(i.next())


# 方法二：Python 栈+迭代，5行代码简单易理解
class NestedIterator2:
    def __init__(self, nestedList: [NestedInteger]):
        # 对于nestedList中的内容，我们需要从左往右遍历，
        # 但堆栈pop是从右端开始，所以我们压栈的时候需要将nestedList反转再压栈
        self.stack = nestedList[::-1]

    def next(self) -> int:
        # hasNext 函数中已经保证栈顶是integer，所以直接返回pop结果
        return self.stack.pop(-1).getInteger()

    def hasNext(self) -> bool:
        # 对栈顶进行‘剥皮’，如果栈顶是List，把List反转再依次压栈，
        # 然后再看栈顶，依次循环直到栈顶为Integer。
        # 同时可以处理空的List，类似[[[]],[]]这种test case
        while len(self.stack) > 0 and self.stack[-1].isInteger() is False:
            self.stack += self.stack.pop().getList()[::-1]
        return len(self.stack) > 0


# 方法三：只需要关注下isInteger、getList两个方法，
# 然后这就变成了一道简单递归题
class NestedIterator:
    def __init__(self, nestedList: [NestedInteger]):
        self.lists = []
        self.point = 0

        def get_list(n):
            for i in n:
                if i.isInteger():
                    self.lists.append(i.getInteger())
                else:
                    get_list(i.getList())
        get_list(nestedList)

    def next(self) -> int:
        self.point += 1
        return self.lists[self.point - 1]

    def hasNext(self) -> bool:
        if self.point < len(self.lists):
            return True
        return False


def deserialize(s: str) -> NestedInteger:
    if s[0] != '[':
        return NestedInteger(int(s))
    stack, num, negative = [], 0, False
    for i, c in enumerate(s):
        if c == '-':
            negative = True
        elif c.isdigit():
            num = num * 10 + int(c)
        elif c == '[':
            stack.append(NestedInteger())
        elif c in ',]':
            if s[i-1].isdigit():
                if negative:
                    num = -num
                stack[-1].add(NestedInteger(num))
            num, negative = 0, False
            if c == ']' and len(stack) > 1:
                stack[-2].add(stack.pop())
    return stack.pop()


def intToString(input):
    if input is None:
        input = 0
    return str(input)

def nestedIntegerToString(nestedInteger):
    if nestedInteger.isInteger():
        return intToString(nestedInteger.getInteger())
    else:
        serializedNestedIntegers = []
        for ni in nestedInteger.getList():
            serializedNestedInteger = nestedIntegerToString(ni)
            serializedNestedIntegers.append(serializedNestedInteger)
        return "[{}]".format(', '.join(serializedNestedIntegers))

def main():
    import sys
    import io
    def readlines():
        for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
            yield line.strip('\n')

    lines = readlines()
    while True:
        try:
            line = next(lines)
            line_json = json.loads(line)

            nestedList = []
            for i in line_json:
                i = str(i)
                print(nestedIntegerToString(deserialize(i)))
                nestedList.append(deserialize(i))

            print(nestedList, type(nestedList))

            i, v = NestedIterator(nestedList), []
            while i.hasNext(): v.append(i.next())
            print(v)

        except StopIteration:
            break


if __name__ == '__main__':
    main()